function loadscript(longitude, latitude)
{
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://api.map.baidu.com/api?v=2.0&ak=RfYi5LFm8OtfKdcUiVPqTfC0ucVV3ElG&callback=init(longitude, latitude)";
	document.body.appendChild(script);
}
function init(longitude, latitude)
{
	var map = new BMap.Map("baidu");
	var point = new BMap.Point(longitude, latitude);
	var myIcon = new BMap.Icon("http://developer.baidu.com/map/jsdemo/img/fox.gif", new BMap.Size(300,157));
	var marker2 = new BMap.Marker(point);
	var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});
	var navigationControl = new BMap.NavigationControl({
			anchor: BMAP_ANCHOR_TOP_LEFT,
			type: BMAP_NAVIGATION_CONTROL_LARGE
		  });
	var geolocationControl = new BMap.GeolocationControl();
	geolocationControl.addEventListener("locationSuccess", function(e){
		var address = '';
		address += e.addressComponent.province;
		address += e.addressComponent.city;
		address += e.addressComponent.district;
		address += e.addressComponent.street;
		address += e.addressComponent.streetNumber;
		alert("当前定位地址为：" + address);
	});
	geolocationControl.addEventListener("locationError", function(e){
		alert(e.message);
	})
	map.centerAndZoom(point, 8);
	map.addOverlay(marker2);
	marker2.setAnimation(BMAP_ANIMATION_BOUNCE);
	map.addControl(new BMap.MapTypeControl());
	map.addControl(top_left_control);
	map.addControl(navigationControl);
	map.addControl(geolocationControl);
	map.enableScrollWheelZoom(true);
	return map;
}

function history_line(longitude, latitude)
{
	var beijingPosition=new BMap.Point(116.432045,39.910683),
	hangzhouPosition=new BMap.Point(120.129721,30.314429),
	taiwanPosition=new BMap.Point(121.491121,25.127053),
	ship_location = new BMap.Point(longitude, latitude);
	var points = [beijingPosition,hangzhouPosition, taiwanPosition, ship_location];
	var curve = new BMapLib.CurveLine(points, {strokeColor:"black", strokeWeight:3, strokeOpacity:0.5}); //创建弧线对象
	map = init(longitude, latitude);
	map.addOverlay(curve);
}

function ship_location(longitude, latitude)
{
	map = init(longitude, latitude);
}

var longitude = 120.2;
var latitude = 30.3;
window.onload = loadscript(longitude, latitude);

function get_ship_location(ship_id)
{
	url = 'ship_id/'+ship_id;
	$.ajax({
		url: url,
		dataType: 'json',
		success: function(data){
			history_line(data['longitude'], data['latitude']);
		},
		error:function(data){
		}
	});
}